﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using System.Text;
using ZhimeiSoft.Framework.Client.Base;
using ZhimeiSoft.Framework.Common.RefectUtils;
using ZhimeiSoft.CharmManager.Client.Manager;
using System.Threading;
using System.Windows.Forms;


namespace ZhimeiSoft.CharmManager.Client.App
{
    public class CharmManagerApp : ClientAppBase
    {
        public CharmManagerApp()
        {
            
        }

        public override ILoginForm CreateLoginForm()
        {
            ILoginForm loginForm;
            Assembly assembly = typeof(ILoginForm).Assembly;
            loginForm = (ILoginForm)ReflectHelper.Instance.CreateObject(assembly,
                            @"ZhimeiSoft.CharmManager.Client.Forms",
                            @"ZhimeiSoft.CharmManager.Client.Forms.frmLogin",
                            new object[] { });
            return loginForm;
        }

        public override IMainForm CreateMainForm()
        {
            IMainForm mainForm;
            Assembly assembly = typeof(IMainForm).Assembly;
            mainForm = (IMainForm)ReflectHelper.Instance.CreateObject(assembly,
                @"ZhimeiSoft.CharmManager.Client.Forms",
                @"ZhimeiSoft.CharmManager.Client.Forms.frmMain",
                new object[] { });
            return mainForm;
        }

        public override IAboutForm CreateAboutForm()
        {
            return base.CreateAboutForm();
        }

        public override IChangePasswordForm CreateChangePasswordForm()
        {
            return base.CreateChangePasswordForm();
        }

        public override bool Run()
        {

            this.Init();
            try
            {
                
                this.InitConnector();

                /*ILoginForm loginForm = this.CreateLoginForm();
                LoginEntity output = loginForm.Login(null);
                if (output == null)
                {
                    return false;
                }

                this.userId = output.UserId;
                this.username = output.UserName;*/
                try
                {
                    string error = string.Empty;
                    BussinessProxyManager.Instance.CheckAllExpiredTodoState(out error);
                    BussinessProxyManager.Instance.CheckAllReservationState(out error);
                }
                catch (Exception ex)
                {
                }

                IMainForm mainForm = this.CreateMainForm();
                mainForm.Execute(this);
                return true;
            }
            finally
            {
            }
        }
    }
}
